<?php

# mvblogs_2-0
# 2006 Oct 10  06:18:07
# request handler

# singleton
class Request
{
    static private $instance;
    private $uri;

    private function __construct()
    {
        $uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']);
        $this->uri = trim($uri, '/');
    }

    static public function getInstance()
    {
        if (!Request::$instance instanceof Request) {
            Request::$instance = new Request();
        }
        return Request::$instance;
    }

    static public function getUri()
    {
        $request = Request::getInstance();
        return $request->uri;
    }

    static public function getMatch()
    {
        $request = Request::getInstance();
        $matches = array(
            array('~^user/settings$~', 'User', 'settings'),
            array('~^profile/view/([0-9])$~', 'Profile', 'view'),
            array('~^blog/view/([0-9])$~', 'Blog', 'view'));

        foreach ($matches as $match)
        {
            if (preg_match($match[0], $request->uri, $mat)) {
                unset($mat[0]);
                return array_merge($match, $mat);
            }
        }
        return false;
    }
}